import * as mobx from 'mobx';
import {WeaTools, WeaLocaleProvider} from 'ecCom';
import {message} from 'antd';
import {WeaTableNew} from 'comsMobx';
import * as WORKFLOW_SHARE from '../../apis/addShare';
const getLabel = WeaLocaleProvider.getLabel;

const { TableStore } = WeaTableNew;

const {observable, action} = mobx;

export default class WFShareStore {

    @observable addShareVisible = false;
    @observable tableStore = new TableStore();
    @observable jurisdiction = false;   //判断是否有权限

    constructor() {
        this.initDatas = this.initDatas;
        this.addDatas = this.addDatas;
        this.deleteDatas = this.deleteDatas;
        this.toggleAddShareVisible = this.toggleAddShareVisible;
    }

    @action
    toggleAddShareVisible = (visible = false) =>  {
        this.addShareVisible = visible;
    }

    initDatas = (params = {}) =>  {
        WORKFLOW_SHARE.doWorkflowShareListPost(params).then((data) => {
            const {sessionkey, isshowdelete} = data;
            this.tableStore.getDatas(sessionkey, params.current || 1);
            this.jurisdiction = isshowdelete;

        })
    }

    addDatas = (params = {}) =>  {
        message.loading(getLabel(383498,'正在添加...请稍候'),0);
        WORKFLOW_SHARE.doWorkflowAddSharePost(params).then((data) => {
            const {sessionkey} = data;
            this.tableStore.getDatas(sessionkey, params.current || 1);
            message.destroy();
            message.success(getLabel(83880,'添加成功'));
        },()=>{
            message.destroy();
            message.error(getLabel(26772,'添加失败'));
        })
    }

    deleteDatas = (params = {}) =>  {
        message.loading(getLabel(84024,'正在删除数据，请稍候...'),0);
        WORKFLOW_SHARE.doWorkflowDeleteSharePost(params).then((data) => {
            const {sessionkey} = data;
            this.tableStore.getDatas(sessionkey, params.current || 1);
            message.destroy();
            message.success(getLabel(20461,'删除成功'));
        },()=>{
            message.destroy();
            message.error(getLabel(83473,'删除失败'));
        })
    }


}

